<template>
  <div class="goods">
    <div class="wrap">
      <Crumb> </Crumb>
      <img src="../assets/img/banner.4c6b6225.png" width="100%" alt="" />
      <ul class="options">
        <li>
          <strong>排序：</strong>
          <span
            :class="{ active: curIndex == index }"
            v-for="(item, index) in options1"
            :key="index"
            @click="choseFn(index, item.min, item.max)"
            >{{ item.txt }}</span
          >
          <!-- <span>我还可以兑换</span>
          <span>0-500个</span>
          <span>500-1000个</span>
          <span>1000-1500个</span>
          <span>1500-2500个</span> -->
        </li>
        <li>
          <strong>分类：</strong>
          <span class="active">全部</span>
          <span>实物礼品</span>
          <span>虚拟礼品</span>
        </li>
      </ul>
      <List :arr="goodsList" />
    </div>
  </div>
</template>                            
<script>
import Crumb from "@/components/Crumb.vue";
import List from "@/components/home/List.vue";
import { getProductsAPI } from "@/request/api";
export default {
  data() {
    return {
      // 商品列表
      goodsList: [],

      // 初始状态
      curIndex: 0,

      // 设置初始状态
      did: 0,
      typ: 1,
      min: 0,
      max: 0,
      keyword: "", //非必须传递的参数

      // 设置排序的数组项
      options1: [
        { min: 0, max: 10000, txt: "全部" },
        // "我还可以兑换"的max值是Header组件的coin值
        { min: 0, max: 0, txt: "我还可以兑换" },
        { min: 0, max: 500, txt: "0-500分" },
        { min: 500, max: 1000, txt: "500-1000分" },
        { min: 1000, max: 1500, txt: "1000-1500分" },
        { min: 1500, max: 2500, txt: "1500-2500分" },
        { min: 2500, max: 6500, txt: "2500-6500分" },
        { min: 6500, max: 10000, txt: "6500-10000分" },
      ],
    };
  },
  created() {
    // 初始状态数据
    this.getProducts();
  },
  components: {
    Crumb,
    List,
  },
  methods: {
    // 发生请求的函数
    async getProducts() {
      let res = await getProductsAPI({
        did: this.did,
        typ: this.typ,
        min: this.min,
        max: this.max,
        keyword: this.keyword,
      });
      // console.log(666, res.data);
      this.goodsList = res.data;
    },

    choseFn(curIndex, curMin, curMax) {
      this.curIndex = curIndex;
      this.min = curMin;
      this.max = curMax;
      // 修改完最小值和最大，重新请求数据
      this.getProducts();
    },
  },
};
</script>
 
<style lang = "less" scoped>
@import "../assets/css/public.less";
@base-color: #0a328e;
.goods {
  padding-bottom: 50px;
  background: #efefef;
  padding-top: 20px;
  .options {
    padding-top: 20px;
    padding-bottom: 40px;
    li {
      margin-top: 20px;
      strong {
        color: #000;
        font-weight: bold;
      }
      span {
        margin-right: 20px;
        margin-left: 10px;
        cursor: pointer;
        color: #999;
        &.active {
          color: @base-color;
          font-weight: bold;
        }
      }
    }
  }
}
</style>